home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / rockola.c < prev    next >
C/C++ Source or Header  |  2000-04-04  |  9KB  |  376 lines

  1. /***************************************************************************
  2.  
  3.   vidhrdw.c
  4.  
  5.   Functions to emulate the video hardware of the machine.
  6.  
  7. ***************************************************************************/
  8.  
  9. #include "driver.h"
  10. #include "vidhrdw/generic.h"
  11.  
  12.  
  13.  
  14. unsigned char *rockola_videoram2;
  15. unsigned char *rockola_characterram;
  16. unsigned char *rockola_scrollx,*rockola_scrolly;
  17. static unsigned char dirtycharacter[256];
  18. static int flipscreen;
  19. static int charbank;
  20. static int backcolor;
  21.  
  22.  
  23. /***************************************************************************
  24.  
  25.   Convert the color PROMs into a more useable format.
  26.  
  27.   Zarzon has a different PROM layout from the others.
  28.  
  29. ***************************************************************************/
  30. void rockola_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
  31. {
  32.     int i;
  33.     #define TOTAL_COLORS(gfxn) (Machine->gfx[gfxn]->total_colors * Machine->gfx[gfxn]->color_granularity)
  34.     #define COLOR(gfxn,offs) (colortable[Machine->drv->gfxdecodeinfo[gfxn].color_codes_start + offs])
  35.  
  36.  
  37.     for (i = 0;i < Machine->drv->total_colors;i++)
  38.     {
  39.         int bit0,bit1,bit2;
  40.  
  41.  
  42.         /* red component */
  43.         bit0 = (*color_prom >> 0) & 0x01;
  44.         bit1 = (*color_prom >> 1) & 0x01;
  45.         bit2 = (*color_prom >> 2) & 0x01;
  46.         *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  47.         /* green component */
  48.         bit0 = (*color_prom >> 3) & 0x01;
  49.         bit1 = (*color_prom >> 4) & 0x01;
  50.         bit2 = (*color_prom >> 5) & 0x01;
  51.         *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  52.         /* blue component */
  53.         bit0 = 0;
  54.         bit1 = (*color_prom >> 6) & 0x01;
  55.         bit2 = (*color_prom >> 7) & 0x01;
  56.         *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  57.  
  58.         color_prom++;
  59.     }
  60.  
  61.  
  62.     backcolor = 0;    /* background color can be changed by the game */
  63.  
  64.     for (i = 0;i < TOTAL_COLORS(0);i++)
  65.         COLOR(0,i) = i;
  66.  
  67.     for (i = 0;i < TOTAL_COLORS(1);i++)
  68.     {
  69.         if (i % 4 == 0) COLOR(1,i) = 4 * backcolor + 0x20;
  70.         else COLOR(1,i) = i + 0x20;
  71.     }
  72. }
  73.  
  74. void satansat_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
  75. {
  76.     int i;
  77.     #define TOTAL_COLORS(gfxn) (Machine->gfx[gfxn]->total_colors * Machine->gfx[gfxn]->color_granularity)
  78.     #define COLOR(gfxn,offs) (colortable[Machine->drv->gfxdecodeinfo[gfxn].color_codes_start + offs])
  79.  
  80.  
  81.     for (i = 0;i < Machine->drv->total_colors;i++)
  82.     {
  83.         int bit0,bit1,bit2;
  84.  
  85.  
  86.         /* red component */
  87.         bit0 = (*color_prom >> 0) & 0x01;
  88.         bit1 = (*color_prom >> 1) & 0x01;
  89.         bit2 = (*color_prom >> 2) & 0x01;
  90.         *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  91.         /* green component */
  92.         bit0 = (*color_prom >> 3) & 0x01;
  93.         bit1 = (*color_prom >> 4) & 0x01;
  94.         bit2 = (*color_prom >> 5) & 0x01;
  95.         *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  96.         /* blue component */
  97.         bit0 = 0;
  98.         bit1 = (*color_prom >> 6) & 0x01;
  99.         bit2 = (*color_prom >> 7) & 0x01;
  100.         *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  101.  
  102.         color_prom++;
  103.     }
  104.  
  105.  
  106.     backcolor = 0;    /* background color can be changed by the game */
  107.  
  108.     for (i = 0;i < TOTAL_COLORS(0);i++)
  109.         COLOR(0,i) = 4 * (i % 4) + (i / 4);
  110.  
  111.     for (i = 0;i < TOTAL_COLORS(1);i++)
  112.     {
  113.         if (i % 4 == 0) COLOR(1,i) = backcolor + 0x10;
  114.         else COLOR(1,i) = 4 * (i % 4) + (i / 4) + 0x10;
  115.     }
  116. }
  117.  
  118.  
  119.  
  120. WRITE_HANDLER( rockola_characterram_w )
  121. {
  122.     if (rockola_characterram[offset] != data)
  123.     {
  124.         dirtycharacter[(offset / 8) & 0xff] = 1;
  125.         rockola_characterram[offset] = data;
  126.     }
  127. }
  128.  
  129.  
  130.  
  131. WRITE_HANDLER( rockola_flipscreen_w )
  132. {
  133.     /* bits 0-2 select background color */
  134.     if (backcolor != (data & 7))
  135.     {
  136.         int i;
  137.  
  138.  
  139.         backcolor = data & 7;
  140.  
  141.         for (i = 0;i < 32;i += 4)
  142.             Machine->gfx[1]->colortable[i] = Machine->pens[4 * backcolor + 0x20];
  143.  
  144.         memset(dirtybuffer,1,videoram_size);
  145.     }
  146.  
  147.     /* bit 3 selects char bank */
  148.     if (charbank != ((~data & 0x08) >> 3))
  149.     {
  150.         charbank = (~data & 0x08) >> 3;
  151.         memset(dirtybuffer,1,videoram_size);
  152.     }
  153.  
  154.     /* bit 7 flips screen */
  155.     if (flipscreen != (data & 0x80))
  156.     {
  157.         flipscreen = data & 0x80;
  158.         memset(dirtybuffer,1,videoram_size);
  159.     }
  160. }
  161.  
  162.  
  163. WRITE_HANDLER( satansat_b002_w )
  164. {
  165.     /* bit 0 flips screen */
  166.     if (flipscreen != (data & 0x01))
  167.     {
  168.         flipscreen = data & 0x01;
  169.         memset(dirtybuffer,1,videoram_size);
  170.     }
  171.  
  172.     /* bit 1 enables interrups */
  173.     /* it controls only IRQs, not NMIs. Here I am affecting both, which */
  174.     /* is wrong. */
  175.     interrupt_enable_w(0,data & 0x02);
  176.  
  177.     /* other bits unused */
  178. }
  179.  
  180.  
  181.  
  182. WRITE_HANDLER( satansat_backcolor_w )
  183. {
  184.     /* bits 0-1 select background color. Other bits unused. */
  185.     if (backcolor != (data & 3))
  186.     {
  187.         int i;
  188.  
  189.  
  190.         backcolor = data & 3;
  191.  
  192.         for (i = 0;i < 16;i += 4)
  193.             Machine->gfx[1]->colortable[i] = Machine->pens[backcolor + 0x10];
  194.  
  195.         memset(dirtybuffer,1,videoram_size);
  196.     }
  197. }
  198.  
  199.  
  200.  
  201. /***************************************************************************
  202.  
  203.   Draw the game screen in the given osd_bitmap.
  204.   Do NOT call osd_update_display() from this function, it will be called by
  205.   the main emulation engine.
  206.  
  207. ***************************************************************************/
  208. void rockola_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  209. {
  210.     int offs;
  211.  
  212.  
  213.     /* for every character in the Video RAM, check if it has been modified */
  214.     /* since last time and update it accordingly. */
  215.     for (offs = videoram_size - 1;offs >= 0;offs--)
  216.     {
  217.         if (dirtybuffer[offs])
  218.         {
  219.             int sx,sy;
  220.  
  221.  
  222.             dirtybuffer[offs] = 0;
  223.  
  224.             sx = offs % 32;
  225.             sy = offs / 32;
  226.             if (flipscreen)
  227.             {
  228.                 sx = 31 - sx;
  229.                 /* Pioner Balloon has a visible area different from all the others */
  230.                 if (Machine->drv->visible_area.max_y == 28*8-1)
  231.                     sy = 27 - sy;
  232.                 else
  233.                     sy = 31 - sy;
  234.             }
  235.  
  236.             drawgfx(tmpbitmap,Machine->gfx[1],
  237.                     videoram[offs] + 256 * charbank,
  238.                     (colorram[offs] & 0x38) >> 3,
  239.                     flipscreen,flipscreen,
  240.                     8*sx,8*sy,
  241.                     0,TRANSPARENCY_NONE,0);
  242.         }
  243.     }
  244.  
  245.  
  246.     /* copy the background graphics */
  247.     {
  248.         int scrollx,scrolly;
  249.  
  250.  
  251.         scrollx = -*rockola_scrolly;
  252.         scrolly = -*rockola_scrollx;
  253.         if (flipscreen)
  254.         {
  255.             scrollx = -scrollx;
  256.             /* Pioner Balloon has a visible area different from all the others */
  257.             if (Machine->drv->visible_area.max_y == 28*8-1)
  258.                 scrolly = -scrolly - 32;
  259.             else
  260.                 scrolly = -scrolly;
  261.         }
  262.         copyscrollbitmap(bitmap,tmpbitmap,1,&scrollx,1,&scrolly,&Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  263.     }
  264.  
  265.  
  266.     /* draw the frontmost playfield. They are characters, but draw them as sprites */
  267.     for (offs = videoram_size - 1;offs >= 0;offs--)
  268.     {
  269.         int charcode;
  270.         int sx,sy;
  271.  
  272.  
  273.         charcode = rockola_videoram2[offs];
  274.  
  275.         /* decode modified characters */
  276.         if (dirtycharacter[charcode] != 0)
  277.         {
  278.             decodechar(Machine->gfx[0],charcode,rockola_characterram,
  279.                     Machine->drv->gfxdecodeinfo[0].gfxlayout);
  280.             dirtycharacter[charcode] = 0;
  281.         }
  282.  
  283.         sx = offs % 32;
  284.         sy = offs / 32;
  285.         if (flipscreen)
  286.         {
  287.             sx = 31 - sx;
  288.             /* Pioner Balloon has a visible area different from all the others */
  289.             if (Machine->drv->visible_area.max_y == 28*8-1)
  290.                 sy = 27 - sy;
  291.             else
  292.                 sy = 31 - sy;
  293.         }
  294.  
  295.         drawgfx(bitmap,Machine->gfx[0],
  296.                 charcode,
  297.                 colorram[offs] & 0x07,
  298.                 flipscreen,flipscreen,
  299.                 8*sx,8*sy,
  300.                 &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  301.     }
  302. }
  303.  
  304.  
  305. /* Zarzon's background doesn't scroll, and the color code selection is different. */
  306. void satansat_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  307. {
  308.     int offs;
  309.  
  310.  
  311.     /* for every character in the Video RAM, check if it has been modified */
  312.     /* since last time and update it accordingly. */
  313.     for (offs = videoram_size - 1;offs >= 0;offs--)
  314.     {
  315.         if (dirtybuffer[offs])
  316.         {
  317.             int sx,sy;
  318.  
  319.  
  320.             dirtybuffer[offs] = 0;
  321.  
  322.             sx = offs % 32;
  323.             sy = offs / 32;
  324.             if (flipscreen)
  325.             {
  326.                 sx = 31 - sx;
  327.                 sy = 27 - sy;
  328.             }
  329.  
  330.             drawgfx(tmpbitmap,Machine->gfx[1],
  331.                     videoram[offs],
  332.                     (colorram[offs] & 0x0c) >> 2,
  333.                     flipscreen,flipscreen,
  334.                     8*sx,8*sy,
  335.                     &Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  336.         }
  337.     }
  338.  
  339.     /* copy the temporary bitmap to the screen */
  340.     copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  341.  
  342.     /* draw the frontmost playfield. They are characters, but draw them as sprites */
  343.     for (offs = videoram_size - 1;offs >= 0;offs--)
  344.     {
  345.         int charcode;
  346.         int sx,sy;
  347.  
  348.  
  349.         charcode = rockola_videoram2[offs];
  350.  
  351.         /* decode modified characters */
  352.         if (dirtycharacter[charcode] != 0)
  353.         {
  354.             decodechar(Machine->gfx[0],charcode,rockola_characterram,
  355.                     Machine->drv->gfxdecodeinfo[0].gfxlayout);
  356.             dirtycharacter[charcode] = 0;
  357.         }
  358.  
  359.         sx = offs % 32;
  360.         sy = offs / 32;
  361.         if (flipscreen)
  362.         {
  363.             sx = 31 - sx;
  364.             sy = 27 - sy;
  365.         }
  366.  
  367.         drawgfx(bitmap,Machine->gfx[0],
  368.                 charcode,
  369.                 colorram[offs] & 0x03,
  370.                 flipscreen,flipscreen,
  371.                 8*sx,8*sy,
  372.                 &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  373.  
  374.     }
  375. }
  376.